package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.StoreDetail;
import com.addplus.townmall.server.api.model.town.expand.StoreDetailExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 商城店铺详细表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface StoreDetailMapper extends BaseAddMapper<StoreDetail> {

    /**
      * 方法描述：通过商品主键id获取对应店铺详情信息
      *
      * @author zhangjiehang
      * @param shopProductId 商品主键id
      * @return StoreDetail
      * @date 2018/9/6 下午10:27
      * @throws Exception
      */
    @Select("SELECT\n" +
            " sd.id,\n" +
            " sd.store_id,\n" +
            " s.store_name,\n" +
            " s.icon_path,\n" +
            " sd.collect_count+sd.collect_virtual_count as collect_count,\n" +
            " sd.shop_count,\n" +
            " sd.overall_rate,\n" +
            " sd.shop_rate,\n" +
            " sd.service_rate,\n" +
            " sd.logistics_rate \n" +
            "FROM\n" +
            " store_detail sd\n" +
            " LEFT JOIN shop_product sp ON sp.store_id = sd.store_id AND sp.is_deleted = 0\n" +
            " LEFT JOIN store s on s.id = sd.store_id AND s.is_delete = 0\n" +
            "WHERE\n" +
            " sp.id = #{shopProductId}\n" +
            " AND sd.is_deleted = 0 ")
    StoreDetailExpand getStoreDetailByShopProductId(@Param("shopProductId") Integer shopProductId);


    /**
     * 方法描述：通过商店主键id获取对应店铺详情信息
     *
     * @param storeId 店铺主键id
     * @return StoreDetail
     * @throws Exception
     * @author zhangjiehang
     * @date 2018/9/6 下午10:27
     */
    @Select("SELECT\n" +
            " sd.id,\n" +
            " sd.store_id,\n" +
            " s.store_name,\n" +
            " s.icon_path,\n" +
            " sd.collect_count+sd.collect_virtual_count as collect_count,\n" +
            " sd.shop_count,\n" +
            " sd.overall_rate,\n" +
            " sd.shop_rate,\n" +
            " sd.service_rate,\n" +
            " sd.logistics_rate \n" +
            "FROM\n" +
            " store_detail sd\n" +
            " LEFT JOIN store s on s.id = sd.store_id AND s.is_delete = 0\n" +
            "WHERE\n" +
            " sd.store_id = #{storeId}\n" +
            " AND sd.is_deleted = 0 ")
    StoreDetailExpand getStoreDetailById(@Param("storeId") Integer storeId);


    /**
     * 方法描述：通过拼团商品主键id获取对应店铺详情信息
     *
     * @param shopProductFightId 商品主键id
     * @return StoreDetail
     * @throws Exception
     * @author zhangjiehang
     * @date 2018/9/6 下午10:27
     */
    @Select("SELECT\n" +
            " sd.id,\n" +
            " sd.store_id,\n" +
            " s.store_name,\n" +
            " s.icon_path,\n" +
            " sd.collect_count+sd.collect_virtual_count as collect_count,\n" +
            " sd.shop_count,\n" +
            " sd.overall_rate,\n" +
            " sd.shop_rate,\n" +
            " sd.service_rate,\n" +
            " sd.logistics_rate \n" +
            "FROM\n" +
            " store_detail sd\n" +
            " LEFT JOIN shop_product_fight sp ON sp.store_id = sd.store_id AND sp.is_deleted = 0\n" +
            " LEFT JOIN store s on s.id = sd.store_id AND s.is_delete = 0\n" +
            "WHERE\n" +
            " sp.id = #{shopProductFightId}\n" +
            " AND sd.is_deleted = 0 ")
    StoreDetailExpand getStoreDetailByShopProductFightId(@Param("shopProductFightId") Integer shopProductFightId);

}
